<div class="ibox-tools">
    <button class="btn btn-primary " data-toggle="modal" data-target="#excel" type="button"><i class="fa fa-external-link"></i>&nbsp;导出</button>
</div>
<table class="table table-striped table-bordered table-hover ">
    <thead>
        <tr>
        	<th noWrap class="">序号</th>
        	{%foreach $column_title as $item%}
                {%if $item.intable == 1%}
                    {%if $item.sort_code == null && $item.sort_code == ""%}
                        <th noWrap class="">{%$item.name%}</th>
                    {%else%}
                        {%if $item.sort_code == $sort_code%}
                            {%if $sortorder == desc%}
                                <th noWrap class="caret_click caret_sort_down" sort_code = "{%$item.sort_code%}">{%$item.name%}</th> 
                            {%else%}
                                <th noWrap class="caret_click caret_sort_up" sort_code = "{%$item.sort_code%}">{%$item.name%}</th>
                            {%/if%}
                        {%else%}
                            <th noWrap class="caret_click caret_sort" sort_code = "{%$item.sort_code%}">{%$item.name%}</th> 
                        {%/if%}
                    {%/if%}
            			
                {%/if%}
        	{%/foreach%}
        	{%if $table_operation == "true"%}
    			<th noWrap class="">
    			操作
    			</th>
    		{%/if%}
        </tr>
    </thead>
    <tbody>
    	{%foreach from=$data_list key=key item=item%}
    		<tr>
    			<td>{%$key+1+(($page.page_code-1)*$page.page_size)%}</td>
    			{%foreach from=$column_title item=item_title name=loop%}
                    {%assign var="title_key" value=$item_title.key%}
    				{%assign var="show_key" value=$item_title.show_key%}
    				{%assign var="editable" value=$item_title.editable%}
                    {%if $title_key%}
                    {%assign var="value" value=$item.$title_key%}
                    {%/if%}

    				
					{%if $item_title.intable == 1%}
                        {%if $item_title.type == text%}
    	        			<td title="{%$value%}">{%$value%}</td>
    	        		{%else if $item_title.type == time%}
    						<td noWrap title="{%$value|date_format:"%Y-%m-%d %H:%M:%S"%}">{%$value|date_format:"%Y-%m-%d"%}<br>{%$value|date_format:"%H:%M:%S"%}</td>
    					{%else if $item_title.type == number%}
    						<td title="{%$value%}">{%$value%}</td>
    					{%else if $item_title.type == enum%}
    						<td title="{%$item.$show_key%}">{%$item.$show_key%}</td>
    	        		{%else if $item_title.type == custom%}
                            {%if $value != null %}
    	        			<td title="{%$item_title.customMap[$value]%}">{%$item_title.customMap[$value]%}</td>
                            {%else%}
                            <td>{%$value%}</td>
                            {%/if%}
                        {%else if $item_title.type == location%}
                            <td>yyyy</td>
                        {%else if $item_title.type == img%}
                            <td><a href="javascript:void(0);" class="imgTab_btn"><img width="30" src="{%$item.$show_key%}"></a></td>
                        {%else if $item_title.type == richtext%}
                            <td>{%$value%}</td>
    	        		{%/if%}
                    {%/if%}

        		{%/foreach%}
        		{%if $table_operation == "true"%}
					<td>
					{%foreach $table_btn as $item_btn%}
						<a href="{%$item_btn.url%}"  class="{%$item_btn.type%}" data-pk="{%$item[$data_key]%}" data-target="{%$item_btn.data_target%}" data-toggle="{%$item_btn.data_toggle%}">{%$item_btn.text%}</a>
					{%/foreach%}
					</td>
				{%/if%}
			</tr>
        {%foreachelse%}
        <tr>
            <td colspan="1000">没有数据</td>
        </tr>  
    	{%/foreach%}
        
    	{%assign var="column_title" json_encode($column_title)%}
        {%assign var="data_list" json_encode($data_list)%}
    	<script type="text/javascript">
    		var column_title = {%$column_title%}; //表格表头数据
            var data_list = {%$data_list%};  //表格body数据
            var pk_key = '{%$data_key%}';   //表格的主键
            var data_name = '{%$data_name%}'; //数据名称
            var sortorder = '{%$sortorder%}';   //排序方向     ---desc升序   ---asc降序
            $(".caret_click").click(function(){ //点击实现排序
                var loc_search = location.search;
                var sort_code = $(this).attr("sort_code");
                 toSort(sort_code,sortorder);
            })

            function toSort(sort_code,sortorder){
                sortorder = sortorder=='asc'?'desc':'asc' ; 
                var url = location.pathname+location.search ; 
                url = delQueStr(url,'sort_code') ;
                url = delQueStr(url,'sortorder') ; 

                var paramStr = 'sort_code='+sort_code+'&sortorder='+sortorder ; 
                if(url.indexOf('?')>0){

                    location.href = url+'&'+paramStr ; 
                }else{
                    location.href = url+'?'+paramStr ; 
                }

            }

            function delQueStr(url, ref) //删除参数值
            {
                var str = "";

                if (url.indexOf('?') != -1)
                    str = url.substr(url.indexOf('?') + 1);
                else
                    return url;
                var arr = "";
                var returnurl = "";
                var setparam = "";
                if (str.indexOf('&') != -1) {
                    arr = str.split('&');
                    for (i in arr) {
                        if (arr[i].split('=')[0] != ref) {
                            returnurl = returnurl + arr[i].split('=')[0] + "=" + arr[i].split('=')[1] + "&";
                        }
                    }
                    return url.substr(0, url.indexOf('?')) + "?" + returnurl.substr(0, returnurl.length - 1);
                }
                else {
                    arr = str.split('=');
                    if (arr[0] == ref)
                        return url.substr(0, url.indexOf('?'));
                    else
                        return url;
                }
            }
           
    	</script>
    </tbody>
</table>